/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef LIB2D_HARD_SOFT_RENDERER_H
#define LIB2D_HARD_SOFT_RENDERER_H

#include <lib2d/hard/Renderer.h>
#include <WindowImpl.h>
#include <Array2D.h>

namespace liba
{
namespace lib2d
{
namespace hard
{
namespace directx8
{

class Image;

class Renderer : public hard::Renderer
{
public:
	Renderer( LPDIRECT3D8 direct3d, int adapter_number );
	virtual ~Renderer()
	{}

	virtual bool set_mode( WindowImpl * window_impl, int resolution_x, int resolution_y, bool fullscreen);
	virtual void stop_mode();

	virtual void fill( const Rect & rect, const ColorPacked & color);
	virtual void flip();

	virtual int get_height()const;
	virtual int get_width()const;

	virtual void start_scene( const Rect & rect );
	virtual void finish_scene();

	virtual pictureformat::Format get_format()const
	{
		return pictureformat::A8R8G8B8;
	}

	virtual pictureformat::Format get_associated_format( pictureformat::Format format )const
	{
		return pictureformat::A8R8G8B8;
	}

	virtual hard::Image * create_image( int sx, int sy, pictureformat::Format format );

	virtual void draw_rect( const Rect & rect, const ColorPacked & color );
	virtual void draw_line( int x1, int y1, int x2, int y2, const ColorPacked & color );

	virtual void set_gamma( int gamma );

	void blit( Image * image, const Vector2 & dst, const Rect & rect, int alpha );
	void fill_image( Image * image, const Rect & dst_rect, const Rect & src_rect, int alpha );

private:
	void report_device_memory();

	RECT current_rect;
	LONG window_styles;
	D3DPRESENT_PARAMETERS present_parameters; 

	int width;
	int height;
};

} //namespace directx8
} //namespace hard
} //namespace lib2d
} //namespace liba

using namespace liba;

#endif //LIB2D_HARD_SOFT_RENDERER_H

